package com.audition.thread;

import com.sun.glass.ui.Size;

import java.util.LinkedList;

/**
 * @author xukang
 * @date 2021-03-08 15:36
 */
public class MyBlockingQueue {
    int maxSize;
    private LinkedList<Object> storage;

    public MyBlockingQueue(int size) {
        this.maxSize = size;
        storage = new LinkedList<>();
    }

    public synchronized void put(Object o) throws InterruptedException {
        while (storage.size() == maxSize) {
            wait();
        }
        storage.add(o);
        notifyAll();
    }

    public synchronized void take() throws InterruptedException {
        while (storage.size() == 0) {
            wait();
        }
        System.out.println(storage.remove());
        notifyAll();
    }
}
